﻿Imports System.Configuration

Namespace Configuration

    Public Class SiteElement
        Inherits ConfigurationElement

        <ConfigurationProperty("Id", IsRequired:=False)> _
        Public Property Id() As Guid
            Get
                Return Me("Id")
            End Get
            Set(ByVal value As Guid)
                Me("Id") = value
            End Set
        End Property

        <ConfigurationProperty("Name", IsKey:=True, IsRequired:=True)> _
        Public Property Name() As String
            Get
                Return DirectCast(Me("Name"), String)
            End Get
            Set(ByVal value As String)
                Me("Name") = value
            End Set
        End Property

        <ConfigurationProperty("Code", IsRequired:=True)> _
        Public Property Code() As String
            Get
                Return DirectCast(Me("Code"), String)
            End Get
            Set(ByVal value As String)
                Me("Code") = value
            End Set
        End Property

        <ConfigurationProperty("Roles")> _
        Public ReadOnly Property Roles() As RoleCollection
            Get
                Return DirectCast((Me("Roles")), RoleCollection)
            End Get
        End Property

        <ConfigurationProperty("Contacts")> _
        Public ReadOnly Property Contacts() As ContactCollection
            Get
                Return DirectCast(Me("Contacts"), ContactCollection)
            End Get
        End Property

        <ConfigurationProperty("Forms")> _
        Public ReadOnly Property Forms() As FormCollection
            Get
                Return DirectCast(Me("Forms"), FormCollection)
            End Get
        End Property

    End Class

    <ConfigurationCollection(GetType(SiteElement))> _
    Public Class SiteCollection
        Inherits ConfigurationElementCollection
        Protected Overloads Overrides Function CreateNewElement() As ConfigurationElement
            Return New SiteElement()
        End Function

        Protected Overloads Overrides Function GetElementKey(ByVal element As ConfigurationElement) As Object
            Return DirectCast((element), SiteElement).Name
        End Function

        Default Public Shadows ReadOnly Property Item(ByVal idx As Integer) As SiteElement
            Get
                Return DirectCast(BaseGet(idx), SiteElement)
            End Get
        End Property
    End Class


End Namespace
